package com.atguigu.guli.service.base.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @desc Swagger2配置文件
 * @auther Administrator
 * @create 2020/5/16
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webAiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
    }

    @Bean
    public Docket adminApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("adminApi")
                .apiInfo(adminAiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }

    /**
     * webApi文档配置
     * @return
     */
    private ApiInfo webAiInfo(){
        return new ApiInfoBuilder()
                .title("谷粒学院网站API文档")
                .description("本文描述了谷粒学院网站的API接口定义")
                .version("1.0")
                .contact(new Contact("zero", "stathunt.com", "zero.qq.com"))
                .build();
    }

    /**
     * webApi文档配置
     * @return
     */
    private ApiInfo adminAiInfo(){
        return new ApiInfoBuilder()
                .title("谷粒学院运维后台的API文档")
                .description("本文描述了谷粒学院运维后台的API接口定义")
                .version("1.0")
                .contact(new Contact("zero", "stathunt.com", "zero.qq.com"))
                .build();
    }
}
